package com.example.hospital.service.impl;

import java.util.List;

import com.example.common.util.utils.DateUtils;
import com.example.common.util.utils.StringUtils;
import com.example.hospital.service.HospitalSetService;
import com.example.model.domain.entity.hospital.HospitalSet;
import com.example.model.vo.order.SignInfoVo;
import com.example.model.vo.hospital.HospitalSetQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.hospital.mapper.HospitalSetMapper;


/**
 * 医院设置Service业务层处理
 *
 * @author ruoyi
 * @date 2021-07-08
 */
@Service
public class HospitalSetServiceImpl implements HospitalSetService
{
    @Autowired
    private HospitalSetMapper hospitalSetMapper;

    /**
     * 查询医院设置
     *
     * @param id 医院设置ID
     * @return 医院设置
     */
    @Override
    public HospitalSet selectHospitalSetById(Long id)
    {
        return hospitalSetMapper.selectHospitalSetById(id);
    }


    /**
     * 查询医院设置列表
     * @return 医院设置
     */
    @Override
    public List<HospitalSet> selectHospitalSetList() {
        return hospitalSetMapper.selectHospitalSetList();
    }

    /**
     * 查询医院设置分页
     * @param hospitalSetQueryVo
     * @return
     */
    @Override
    public List<HospitalSet> selectHospitalSetList(HospitalSetQueryVo hospitalSetQueryVo) {
        return hospitalSetMapper.selectHospitalSetPage(hospitalSetQueryVo);
    }

    /**
     * 新增医院设置
     *
     * @param hospitalSet 医院设置
     * @return 结果
     */
    @Override
    public int insertHospitalSet(HospitalSet hospitalSet)
    {
        hospitalSet.setCreateTime(DateUtils.getNowDate());
        return hospitalSetMapper.insertHospitalSet(hospitalSet);
    }

    /**
     * 修改医院设置
     *
     * @param hospitalSet 医院设置
     * @return 结果
     */
    @Override
    public int updateHospitalSet(HospitalSet hospitalSet)
    {
        hospitalSet.setUpdateTime(DateUtils.getNowDate());
        return hospitalSetMapper.updateHospitalSet(hospitalSet);
    }

    /**
     * 批量删除医院设置
     *
     * @param ids 需要删除的医院设置ID
     * @return 结果
     */
    @Override
    public int deleteHospitalSetByIds(Long[] ids)
    {
        return hospitalSetMapper.deleteHospitalSetByIds(ids);
    }



    /**
     * 锁定解锁医院，就是更新
     * @param id
     * @param status
     * @return
     */
    @Override
    public int hospitalSetLocked(Long id, Integer status) {
        return hospitalSetMapper.hospitalSetLocked(id,status);
    }


    /**
     * 根据hospitalCode查询HospitalSign
     * @param hospitalSetCode
     * @return
     */
    @Override
    public String selectSignByHospitalSetCode(String hospitalSetCode) {
        return hospitalSetMapper.selectSignByHospitalSetCode(hospitalSetCode);
    }


    @Override
    public SignInfoVo getSignInfoByHoscode(String hoscode) {
        SignInfoVo signInfoVo = new SignInfoVo();
        HospitalSet hospitalSet = hospitalSetMapper.selectHospitalSetByHoscode(hoscode);
        if (StringUtils.isNotNull(hospitalSet)){
            signInfoVo.setApiUrl(hospitalSet.getApiUrl());
            signInfoVo.setSignKey(hospitalSet.getSignKey());
            return signInfoVo;
        }
        //暂时抛不了异常，奇怪了
        return null;
//        BusinessEnum.HOSPITAL_UNOPEN
//        throw new BaseException("错误");
    }
}
